package com.sure.controller.system;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sure.controller.base.BaseController;
import com.sure.pojo.Group;
import com.sure.service.GroupService;

@Controller
@RequestMapping(value="/group")
public class GroupController extends BaseController {
	
	@Resource(name="GroupService")
	GroupService groupService;
	
	/**
	 * 组织管理页面
	 * @return
	 */
	@RequestMapping(value="/groupMngView")
	public ModelAndView groupMngView()throws Exception{
		ModelAndView mv = new ModelAndView();
		mv.setViewName("system/groupMng");
		return mv;
	}
	
	/**
	 * 获取组织列表
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/getGroups", produces="application/json;charset=UTF-8")
	@ResponseBody
	public Object getGroups()throws Exception{
		
		List<Group> groups = groupService.getGroups();
		
		return groups;
	}
	
	/**
	 * 新增组织
	 * @param group
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/addGroup", produces="application/json;charset=UTF-8")
	@ResponseBody
	public Object addGroup(Group group)throws Exception{
		
		return groupService.addGroup(group);
	}
	
	/**
	 * 编辑组织
	 * @param group
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/editGroup", produces="application/json;charset=UTF-8")
	@ResponseBody
	public Object editGroup(Group group)throws Exception{
		
		return groupService.editGroup(group);
	}
	
	/**
	 * 删除组织
	 * @param groupId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/delGroup", produces="application/json;charset=UTF-8")
	@ResponseBody
	public Object delGroup(int groupId)throws Exception{
		
		return groupService.delGroup(groupId);
	}
}
